package org.example.bookstore.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.bookstore.pojo.DO.Cart;
import org.example.bookstore.pojo.DTO.CartProduct;

import java.util.List;

@Mapper
public interface CartMapper {
    /*
     * 向购物车添加数据
     * */
    @Insert("INSERT INTO book_cart (book_id, book_num, user_id, create_time, update_time) VALUES (#{bookId}, #{bookNum}, #{userId}, #{createTime}, #{updateTime});")
    int insertGoodsToCart(Cart cart);
    /*
     * 获取购物车商品列表
     * */
    @Select("SELECT book_cart.id AS id,\n" +
            "       books.book_name AS bookName,\n" +
            "       books.book_price AS bookPrice,\n" +
            "       books.book_img AS bookImg,\n" +
            "       books.book_intrduce AS bookIntrduce,\n" +
            "       books.book_type AS bookType,\n" +
            "       book_cart.book_num AS bookNum,books.id As BookId\n" +
            "FROM book_cart\n" +
            "JOIN books ON book_cart.book_id = books.id\n" +
            "WHERE book_cart.user_id = #{id};")
    List<CartProduct> selectGoodsList(Integer id);
    /*
     * 删除购物车商品
     * */
    @Delete("delete from book_cart where id=#{id}  ")
    boolean deleteGoods(Integer id);
}
